﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;

namespace VerticalWebSpider
{
    public class HttpTools
    {
        public static Dictionary<string, HttpTools> _Name2Tools = new Dictionary<string, HttpTools>();

        private HttpTools() { }

        /// <summary>
        /// 根据名称获取实例
        ///     实例不同则可以模拟多个请求的客户端
        /// </summary>
        /// <returns>The instance.</returns>
        /// <param name="name">Name.</param>
        public static HttpTools GetInstance(string name)
        {
            if (!_Name2Tools.ContainsKey(name))
            {
                lock (_Name2Tools)
                {
                    if (!_Name2Tools.ContainsKey(name))
                    {
                        _Name2Tools[name] = new HttpTools();
                    }
                }
            }

            return _Name2Tools.TryGetValue(name, out HttpTools tools) ? tools : null;
        }

        public string HttpGet(string url)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";
            request.ContentType = "application/x-www-form-urlencoded";
        }
    }
}
